#!/usr/bin/env bash
database=$1
user=$2
password=$3
time=$(date "+%Y%m%d-%H%M")

path=$4
filter=$5

if [ -z "$path" ]; then
    path="./"
fi

if [ -z "$filter" ]; then
    filter=".json"
fi

echo "source path: $path"
echo "filter: $filter"


ls -l $path | grep ^[^d]  | grep $filter | awk '{print $9}' | awk '{print substr($0,0,length()-4)}' \
  | { readarray ary ; for i in ${ary[@]};  do echo "mongoimport -d $database -u $user -p $password --collection $i --file $path/$i.json && echo '['$i' done！]'";  done  ; } \
  | bash

# 使用方式： docker exec mongo mongo-import.sh album dev 123 /data/db/0 .json
# 3个参数：数据库，用户名，密码
